package com.forum.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @ClassNameSwaggerAutoConfiguration
 * Swgger2接口工具类配置
 * @Author 张继成
 * @Date 2023/11/23 21:13
 */
@Configuration
@EnableSwagger2
public class SwaggerAutoConfiguration {
    //创建用户接口API
    @Bean
    public Docket createUserRestAPI(){
        Docket docket=new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo()).groupName("用户接口组")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.forum.controller"))
                .build();
        return docket;
    }
    //创建菜单接口API
    @Bean
    public Docket createMenuRestAPI(){
        Docket docket=new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo()).groupName("菜单接口组")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.forum.controller"))
                .build();
        return docket;
    }
    //构建api文档的详细信息
    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("API接口文档")   //页面标题
                .contact(new Contact("张继成-毕设","http://www.forum.com",""))
                .version("1.0")        //版本号
                .description("API描述") //描述
                .build();
    }

}
